﻿{% extends "layout.html" %}

{% block title %}
<title>答辩</title>
{% endblock %}

{% block style %}

{% endblock %}

{% block li %}
    <li><a href="content.html">答疑</a></li>
    <li>{{ subject_id }}</li>
{% endblock %}

{% block content %}
		<div class="admin">
				<div class="panel admin-panel">
					<div class="panel-head" onclick="anal(this)"><strong>答疑</strong></div>
                    <div id="anal_problem" style="display: none;height: 120px;padding-top:1px;ppadding-left: 2px;padding-right: 2px;">
                         <form id="ans" action="/add_answer.html/" method="post">
                             <textarea class="form-control" rows="3" name=textarea></textarea>
                             <input type="hidden" name="subject_id" value="{{subject_id}}">
                              <input type="hidden" name="username" value="{{username}}">
                              <a onclick="ans()" style="color: #21a88b;">添加答疑</a>
                         </form>
                    </div>
					<table class="table table-hover">
                     {% for each in answer_lists  %}
                         <tr>
							<td>
                               <div>
                                    {{forloop.counter}}. <a>{{each.problem}}</a>
                               </div>
                                <div style="height: 20px;"></div>
                                <div>
                                    <span style="color: #999;font-size: 12px;line-height: 20px">
                                        {{ each.info.userName }}:&nbsp;&nbsp;发布于 {{ each.time }}
                                    </span>
                                     <a onclick="analyze(this)" style="float: right; color: #21a88b;margin-left: 20px;">
                                              添加解析
                                     </a>
                                </div>
                                <div style="height:10px;clear: both;"></div>
                                <div id="analyze{{ forloop.counter }}" style="display: none;">
                                    <form action="/add_discuss.html/" id="frame{{forloop.counter }}" method="post" target="discuss_frame{{ forloop.counter }}">
                                        <iframe onload="iframeUpload(this)" style="display: none" name="discuss_frame{{ forloop.counter }}" id="discuss_frame{{ forloop.counter }}" src=""></iframe>
                                        <span style="padding-left: 45px;">
                                          <textarea style="width: 798px;" class="form-control" rows="3" name=textarea></textarea>
                                        </span>
                                         <span class="frame{{ forloop.counter }}" onclick="subFrom(this)" style="color: #21a88b;">
                                              发表解析
                                         </span>
                                        <input type="hidden" name="answer_id" value="{{each.pk}}">
                                        <input type="hidden" name="subject_id" value="{{subject_id}}">
                                        <input type="hidden" name="username" value="{{username}}">
                                    </form>
                                </div>
							</td>
						</tr>
                         {% for x in each.comment_set.all%}
                          <tr>
                              <td>
                                  <div>
                                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ x.content }}
                                  </div>
                                  <div style="height: 20px;"></div>
                                  <div>
                                       <span style="color: #999;font-size: 12px;line-height: 20px">
                                           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{x.info.userName}}:&nbsp;&nbsp;发布于{{x.time }}
                                       </span>
                                      <a onclick="answer(this)" style="float: right; color: #21a88b;margin-left: 20px;">

                                      </a>
                                  </div>
                                  <div style="height:10px;"></div>
                                  <div id="answer{{ forloop.counter }}" style="display: none;">
                                      <span style="padding-left: 45px;"><textarea placeholder="请输入你的观点"
                                                style="width: 798px; resize: none; height: 26px;margin: 0px;overflow: hidden;"
                                      ></textarea>
                                      </span>
                                  </div>
                              </td>
                         </tr>
                         {% endfor %}
                         <tr id="tr{{forloop.counter }}">


                         </tr>
                     {% endfor %}

					</table>
				</div>
			<br />
			<p class="text-right text-gray">基于<a class="text-gray" target="_blank" href="http://www.pintuer.com">Python在线学习</a>和答疑系统</p>
		</div>

{% endblock %}

{% block js %}
    <script>
        $(function () {
            $('#question').addClass('active')
            $('#home').removeClass('active')
        });
        var answer = function (obj) {
            //回复
            var atrrs = $(obj).parent().next().next().css("display")
            if(atrrs=="block"){
                $(obj).parent().next().next().css("display","none")
            }else {
                $(obj).parent().next().next().css("display","null")
            }
        }
        var analyze = function (obj) {
            // 添加解析
            var atrrs = $(obj).parent().next().next().css("display")
            if(atrrs=="block"){
                $(obj).parent().next().next().css("display","none")
            }else {
                $(obj).parent().next().next().css("display","null")
            }
            
        }
        var subFrom = function (obj) {
            var par = $(obj).prop('class')
            $(obj).parent().parent().css("display","none")
            $('#'+par).submit()
        }
        var iframeUpload = function (obj) {
            var onload_id = $(obj).prop('id')
            console.log(onload_id)
            var str_json = $('#'+onload_id).contents().find('body').text()
            var attrs = JSON.parse(str_json)
            console.log(""+attrs['current_time'])
            var str =
                '<td>'+
                  '<div>'+
                          '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+attrs['textarea'] +
                      '</div>'+
                      '<div style="height: 20px;"></div>'+
                      '<div>'+
                           '<span style="color: #999;font-size: 12px;line-height: 20px">'+
                               '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+attrs['username']+':&nbsp;&nbsp;发布于'+attrs['current_time']+
                           '</span>'+
                  '</div>'+
                '</td>'
            var index_num = onload_id.charAt(onload_id.length-1)
            $('#tr'+index_num).append(str)

        }
        var anal = function(obj){
            var attrs = $('#anal_problem').css("display")
            console.log(attrs)
             if(attrs=="none"){
                $('#anal_problem').css("display","null")
            }else {
                $('#anal_problem').css("display","none")
            }
        }
        var ans = function () {
            $('#ans').submit()
        }
    </script>
{% endblock %}
</html>